<template>
  <div class="article-portal-container">
    <div class="article-portal-wrapper">
      <div class="article-grid">
        <div 
          v-for="article in articles" 
          :key="article.articleId" 
          class="article-portal-item"
        >
          <div class="article-portal-card">
            <router-link :to="`/article/${article.articleId}`" class="article-link">
              <div class="article-image-box">
                <img 
                  v-if="article.coverImage" 
                  :src="article.coverImage" 
                  :alt="article.title" 
                  class="article-img"
                  loading="lazy"
                >
                <div v-else class="article-img-placeholder">
                  <i class="iconfont icon-picture"></i>
                </div>
                <div class="article-flags">
                  <span v-if="article.isTop === '1'" class="flag-top">置顶</span>
                  <span v-if="article.isHot === '1'" class="flag-hot">热门</span>
                </div>
              </div>
              
              <div class="article-info">
                <h3 class="article-title">{{ article.title }}</h3>
                
                <div class="article-meta">
                  <div class="meta-item">
                    <span class="meta-icon"><i class="iconfont icon-user"></i></span>
                    <span class="meta-text">{{ article.author || '未知作者' }}</span>
                  </div>
                  
                  <div class="meta-item">
                    <span class="meta-icon"><i class="iconfont icon-eye"></i></span>
                    <span class="meta-text">{{ article.viewCount || 0 }}浏览</span>
                  </div>
                  
                  <div class="meta-item">
                    <span class="meta-icon"><i class="iconfont icon-time"></i></span>
                    <span class="meta-text">{{ formatDate(article.publishTime) }}</span>
                  </div>
                </div>
                
                <div class="article-category">
                  <i class="iconfont icon-folder"></i>
                  {{ article.categoryName || '无栏目' }}
                </div>
              </div>
            </router-link>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ArticlePortalGrid',
  props: {
    articles: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    formatDate(dateStr) {
      if (!dateStr) return '未知时间'
      const date = new Date(dateStr)
      const year = date.getFullYear()
      const month = (date.getMonth() + 1).toString().padStart(2, '0')
      const day = date.getDate().toString().padStart(2, '0')
      return `${year}-${month}-${day}`
    }
  }
}
</script>

<style scoped>
/* 基础容器 */
.article-portal-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
  box-sizing: border-box;
}

.article-portal-wrapper {
  width: 100%;
  overflow: hidden;
}

/* 网格布局 */
.article-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin: 0 -10px;
}

/* 每个文章项 */
.article-portal-item {
  padding: 0 10px;
  box-sizing: border-box;
}

.article-portal-card {
  height: 100%;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
}

.article-portal-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
}

.article-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

/* 图片区域 */
.article-image-box {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 60%;
  overflow: hidden;
  background: #f5f7fa;
}

.article-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.article-portal-card:hover .article-img {
  transform: scale(1.05);
}

.article-img-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c0c4cc;
  font-size: 36px;
}

/* 标志标签 */
.article-flags {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.flag-top, .flag-hot {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1;
  border-radius: 10px;
  color: #fff;
}

.flag-top {
  background: rgba(255, 153, 0, 0.8);
}

.flag-hot {
  background: rgba(255, 68, 68, 0.8);
}

/* 文章信息 */
.article-info {
  padding: 15px;
  text-align: center;
}

.article-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 44px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #909399;
}

.meta-item {
  display: flex;
  align-items: center;
}

.meta-icon {
  margin-right: 4px;
  font-size: 12px;
}

.article-category {
  padding: 4px 8px;
  background: #f5f7fa;
  border-radius: 4px;
  font-size: 12px;
  color: #666;
  display: inline-flex;
  align-items: center;
}

.article-category i {
  margin-right: 4px;
  font-size: 12px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .article-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 992px) {
  .article-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .article-grid {
    grid-template-columns: 1fr;
  }
  
  .article-portal-item {
    max-width: 350px;
    margin: 0 auto;
  }
  
  .article-image-box {
    padding-bottom: 50%;
  }
}
</style>